
package site.yunnong.atvris.common.api;

import lombok.Data;

@Data
public class ResultVO<V> extends Result {
    private V data;

    public ResultVO() {
    }

    public ResultVO(Integer code, String message) {
        super.code = code;
        super.message = message;
    }

    public ResultVO(Integer code, String message, V data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public ResultVO success() {
        return this.success((V) null);
    }

    public ResultVO success(V data) {
        this.code = ResultCodeEnum.SUCCESS.getCode();
        this.message = ResultCodeEnum.SUCCESS.getMessage();
        this.data = data;
        return this;
    }

    @Override
    public ResultVO fail() {
        return this.fail(ResultCodeEnum.ERROR_SERVER);
    }

    @Override
    public ResultVO fail(ResultCodeEnum resultCode) {
        return this.fail(resultCode, resultCode.getMessage());
    }

    @Override
    public ResultVO fail(String message) {
        return this.fail(ResultCodeEnum.ERROR_SERVER, message);
    }

    @Override
    public ResultVO fail(ResultCodeEnum resultCode, String message) {
        this.code = resultCode.getCode();
        this.message = message;
        return this;
    }

    public V getData() {
        return this.data;
    }

    public void setData(V data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "ResultVO{data=" + this.data + ", code=" + this.code + ", message='" + this.message + '\'' + '}';
    }
}
